package de.fh.ka.as.car;

import de.fh.ka.as.car.drivecontrol.RealCar;
import de.fh.ka.as.car.drivecontrol.RemoteCar;
import de.fh.ka.as.car.drivecontrol.RemoteControlledCar;
import de.fh.ka.as.car.routing.RoutingMap;
import de.fh.ka.as.car.routing.RoutingMapCar;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class AppStarter extends Activity implements OnClickListener {
	private Button startRealCar, startRemoteCar, startNetworkTest, startRemoteControlledCar, startPreferences,
			sensorTest, routingMap, irTest, routingMapcar;
	public static final String PREFS_NAME = "de.fh.ka.as.carcontrol";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.app_starter);
		startRealCar = (Button) findViewById(R.id.realcar);
		startRealCar.setOnClickListener(this);

		startRemoteCar = (Button) findViewById(R.id.remotecar);
		startRemoteCar.setOnClickListener(this);

		startRemoteControlledCar = (Button) findViewById(R.id.remotecontrolledcar);
		startRemoteControlledCar.setOnClickListener(this);

		startNetworkTest = (Button) findViewById(R.id.networktest);
		startNetworkTest.setOnClickListener(this);

		startPreferences = (Button) findViewById(R.id.preferences);
		startPreferences.setOnClickListener(this);

		sensorTest = (Button) findViewById(R.id.sensortest);
		sensorTest.setOnClickListener(this);

		routingMap = (Button) findViewById(R.id.routingmap);
		routingMap.setOnClickListener(this);

		routingMapcar = (Button) findViewById(R.id.routingmapcar);
		routingMapcar.setOnClickListener(this);

		irTest = (Button) findViewById(R.id.irtest);
		irTest.setOnClickListener(this);

		SharedPreferences setting = getSharedPreferences(PREFS_NAME, 0);
		CarPreferences.setIP_ADDRESS(setting.getString(CarPreferences.KEY_SERVER_IP_ADDRESS, "-"));
	}

	@Override
	public void onClick(View v) {
		Intent intent = null;
		switch (v.getId()) {
			case R.id.realcar:
				intent = new Intent(this, RealCar.class);
				break;
			case R.id.remotecar:
				intent = new Intent(this, RemoteCar.class);
				break;
			case R.id.remotecontrolledcar:
				intent = new Intent(this, RemoteControlledCar.class);
				break;
			case R.id.networktest:
				intent = new Intent(this, NetworkTest.class);
				break;
			case R.id.preferences:
				intent = new Intent(this, CarPreferences.class);
				break;
			case R.id.sensortest:
				intent = new Intent(this, SensorTest.class);
				break;
			case R.id.routingmap:
				intent = new Intent(this, RoutingMap.class);
				break;
			case R.id.irtest:
				intent = new Intent(this, IrTest.class);
				break;
			case R.id.routingmapcar:
				intent = new Intent(this, RoutingMapCar.class);
				break;

		}
		startActivity(intent);
	}

}
